<?php 
if(isset($_REQUEST['fuseaction_back'])) {
	$fuseaction_back=$_REQUEST['fuseaction_back'];
}else{
	$fuseaction_back = "";
}
if(isset($_REQUEST['hdn_worktype'])) {
	$v_worktype = $_REQUEST['hdn_worktype'];
}else{
	$v_worktype = "";
}
$v_customer_record_id = 0;
if(isset($_REQUEST['hdn_customer_record_id'])){
	$v_customer_record_id = $_REQUEST['hdn_customer_record_id'];
}
//Luu giu trang thai loc
$v_receive_date_filter = "";
if(isset($_REQUEST['hdn_received_date_filter'])){
	$v_receive_date_filter = $_REQUEST['hdn_received_date_filter'];
} 
$v_recordtype_filter = $_SESSION['onegate_current_recordtype'];
if(isset($_REQUEST['hdn_recordtype_filter'])){
	$v_recordtype_filter = $_REQUEST['hdn_recordtype_filter'];
}  
//Begin//Xay dung chuoi XML chua gi tri cua 
$v_list_xml_tag = "";
if(isset($_REQUEST['hdn_list_xml_tag'])){
	$v_list_xml_tag = $_REQUEST['hdn_list_xml_tag'];
}
$v_list_xml_value = "";
if(isset($_REQUEST['hdn_list_xml_value'])){
	$v_list_xml_value = $_REQUEST['hdn_list_xml_value'];
}
$strXML = '<?xml version="1.0" encoding="UTF-8"?><root><data_list>';
for ($i=0;$i<_list_get_len($v_list_xml_tag,_CONST_SUB_LIST_DELIMITOR);$i++){
	$strXML = $strXML ."<"._list_get_at($v_list_xml_tag,$i,_CONST_SUB_LIST_DELIMITOR).">";
	$strXML = $strXML .trim(_replace_XML_bad_char(_list_get_at($v_list_xml_value,$i,_CONST_SUB_LIST_DELIMITOR)));
	$strXML = $strXML ."</"._list_get_at($v_list_xml_tag,$i,_CONST_SUB_LIST_DELIMITOR).">";
}
$strXML = $strXML . "</data_list></root>";
//End//Lay danh sach cac the XML va gia tri tuong ung voi tung the do
$v_customer_name= "";
if(isset($_REQUEST['hdn_customer_name'])){
	$v_customer_name = $_REQUEST['hdn_customer_name'];
}
$v_customer_card_id = "";
if(isset($_REQUEST['hdn_customer_card_id'])){
	$v_customer_card_id = $_REQUEST['hdn_customer_card_id'];
}

$v_code= "";
if(isset($_REQUEST['txt_code'])){
	$v_code = _replace_bad_char($_REQUEST['txt_code']);
}

$v_customer_name = $_SESSION['citizen_username'];
$v_customer_card_id = "";
$v_status_of_receiving = 0;
$v_owner_id = $_ISA_OWNER_CODE;
$v_message_id = 0;
/*
// Kiem tra xem nguoi dang nhap hien thoi co quyen thuc hien chuc nang nay hay khong
$function_code = _CONST_ONEGATE_AF_UPDATE;   //Update
if(!_check_permission_on_function($_SESSION['staff_id'], $_ISA_APP_CODE, $function_code)){?>
	<script>
		alert("<? echo _CONST_FUNCTION_PERMISSION_ERROR; ?>");
		if (_MODAL_DIALOG_MODE==1){
			window.location = "<? echo $v_url; ?>";
		}else{
			window.history.back();
		}	
	</script><?
	exit;
}
*/
if(_is_sqlserver()){
	$received_record_xml_date_id = _save_XML_to_database('T_TEMP_FILE', 'PK_TEMP_FILE', 'C_TEXT', $strXML);
	//Cap nhat noi dung cau hoi
	$sql = "Exec Onegate_CustomerRecordUpdate " ;
	$sql = $sql . " " .  $v_customer_record_id ;
	$sql = $sql . ",'" . $v_recordtype_filter . "'"  ;
	$sql = $sql . ",'" . $v_owner_id ."'";
	$sql = $sql . ",'" . $v_customer_name . "'" ;
	$sql = $sql . ",'" . $v_customer_card_id . "'" ;
	$sql = $sql . ",'" . $v_code. "'" ;
	$sql = $sql . "," . $v_status_of_receiving ;
	$sql = $sql . "," .  $received_record_xml_date_id ;
	$sql = $sql . "," . $v_message_id ;
	//echo $sql; exit;
	$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
	$rs = $ado_conn->GetRow($sql); 
	$v_error = _replace_bad_char(trim($rs['RET_ERROR']));
	if($v_customer_record_id <= 0){
		$v_customer_record_id = $rs['NEW_ID'];
	}
}
sleep(0);
if (!is_null($v_error) && $v_error<>""){?>
	<script>
		alert("<?php echo $v_error; ?>");
		if (_MODAL_DIALOG_MODE==1){
			window.location = "<?php echo $v_goto_url; ?>";
		}else{
			window.history.back();
		}	
	</script><?php
	exit;
}
?>
<form action="index.php" method="post" name="f_back">
	<input type="hidden" name="fuseaction" value="DISPLAY_SINGLE_REGISTER_RESULT">
	<input type="hidden" name="hdn_customer_record_id" value="<?php echo $v_customer_record_id;?>">
	<input type="hidden" name="hdn_recordtype_filter" value="<?php echo $v_recordtype_filter; ?>">
	<input type="hidden" name="hdn_customer_name" value="<?php echo $v_customer_name;?>">
	<input type="hidden" name="hdn_customer_card_id" value="<?php echo $v_customer_card_id;?>">
	<input type="hidden" name="hdn_code" value="<?php echo $v_code; ?>">
</form>
<Script language="javascript">
	document.forms(0).submit();
</Script>